package com.sihai.core.support;

import org.hibernate.Query;


/**
 * <code>QueryTotalCountGetter</code> 使用Hibernate {@link org.hibernate.Query} 获得总记录数
 */
public class QueryTotalCountGetter implements TotalcountGetter {

    private Query countQuery;

    public QueryTotalCountGetter(Query countQuery) {
        if (countQuery == null) {
            throw new IllegalArgumentException("count query is null");
        }
        this.countQuery = countQuery;
    }

    @Override
    public int count() {
        return ((Number) this.countQuery.uniqueResult()).intValue();
    }
}
